package org.cnc.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ModelView extends JPanel{
	
    private Graphics bufferGraphics;
    private Image offscreen; 
    protected String title = "View";
    
    public ModelView()
    {
    	this.setPreferredSize(new Dimension(400, 400));
    }
    
	public void updateView( )
	{
		repaint();
	}
	
	public void paintComponent(Graphics g) {

		Graphics2D g2D = (Graphics2D) g;

		int width = getWidth();
		int height = getHeight();
		
		offscreen = createImage(width, height);
	    bufferGraphics = offscreen.getGraphics();
	 
		offscreen.flush();
		bufferGraphics.setColor( Color.DARK_GRAY );
		bufferGraphics.fillRect(0, 0, width, height);
		bufferGraphics.setColor( Color.LIGHT_GRAY );
		
		g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
	

		drawModel( bufferGraphics );
		drawTitle( bufferGraphics );
		
		g2D.drawImage(offscreen,0,0,this);
	}
	
	protected void drawTitle ( Graphics g )
	{
		g.setFont(new Font("Helvetica", Font.BOLD, 14));
		g.setColor( Color.LIGHT_GRAY );
		int width = g.getFontMetrics().stringWidth(title) + 8;
		g.fillRect(0, 0, width, g.getFontMetrics().getHeight() );
		g.setColor( Color.BLACK );
		g.drawString(title, 4, 14);
	}
	
	public void setTitle( String t )
	{
		this.title = t;
	}
	protected void drawModel ( Graphics g )
	{
		
	}
	
	protected void drawCutter ( Graphics g, int gridSize )
	{
		
	}
}